package com.bawei.lib_net.test

import okhttp3.Call
import okhttp3.Callback
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
import retrofit2.Retrofit
import java.io.IOException

/**
 *作者：lxy
 *功能:
 *时间：2025/5/23
 */
class OkHttpDemo {

    fun okHttp() {
        val client = OkHttpClient.Builder().build()
        val request = Request.Builder().url("").get().header("", "").build()

        //call
        val call = client.newCall(request)
        //异步->response
        call.enqueue(object : Callback {
            override fun onFailure(call: Call, e: IOException) {

            }

            override fun onResponse(call: Call, response: Response) {
                //

            }
        })

        //同步->response
        val response = call.execute()
    }


    fun retrofit() {
        val httpClient = OkHttpClient.Builder().build()
        val retrofit = Retrofit
            .Builder()
            .baseUrl("")
            .client(httpClient)
            .build()
        retrofit.create(ApiService::class.java)
    }
}